<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />



  <meta name="google-site-verification" content="6Ik8pGDtBtOTGCKiPW_YXR0Wqp7FfhOllj0Bi92eBDo" />







  <meta name="baidu-site-verification" content="code-uIla4FKPmw" />







  
  
  <link href="/berlinblog/libs/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/berlinblog/libs/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/berlinblog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java,Spring," />





  <link rel="alternate" href="/berlinblog/atom.xml" title="白叁木小肆" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="https://raw.githubusercontent.com/A-limon/pacman/master/source/img/favicon.ico?v=5.1.2" />






<meta name="description" content="浅尝Spring 5">
<meta property="og:type" content="article">
<meta property="og:title" content="浅尝Spring 5">
<meta property="og:url" content="https://berlinwong.gitee.io/berlinblog/2021/09/16/%E6%B5%85%E5%B0%9DSpring5/index.html">
<meta property="og:site_name" content="白叁木小肆">
<meta property="og:description" content="浅尝Spring 5">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923234707.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210916215312.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923141949.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923142417.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923142711.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923212111.png">
<meta property="og:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923233829.png">
<meta property="article:published_time" content="2021-09-16T06:47:10.000Z">
<meta property="article:modified_time" content="2021-10-21T16:54:45.969Z">
<meta property="article:author" content="Berlin">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Spring">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/berlinwong/picgo/raw/master/img/20210923234707.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Gemini',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://berlinwong.gitee.io/berlinblog/2021/09/16/浅尝Spring5/"/>





  <title>浅尝Spring 5 | 白叁木小肆</title>
  














<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta custom-logo">
    

    <div class="custom-logo-site-title">
      <a href="/berlinblog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">白叁木小肆</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">当一个快乐的码农吧！</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/berlinblog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/berlinblog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/berlinblog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/berlinblog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/berlinblog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/berlinblog/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br />
            
            Sitemap
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://berlinwong.gitee.io/berlinblog/berlinblog/2021/09/16/%E6%B5%85%E5%B0%9DSpring5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/berlinblog/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="白叁木小肆">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">浅尝Spring 5</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2021-09-16T14:47:10+08:00">
                2021-09-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/berlinblog/categories/%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90/" itemprop="url" rel="index">
                    <span itemprop="name">原理分析</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          


          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 style="color:#597eb4;">浅尝Spring 5</h1>

<p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923234707.png" alt="image-20210923234706984"></p>
<span id="more"></span>

<h2 id="1-使用Maven导入Spring包"><a href="#1-使用Maven导入Spring包" class="headerlink" title="1. 使用Maven导入Spring包"></a>1. 使用Maven导入Spring包</h2><p><a target="_blank" rel="noopener" href="https://mvnrepository.com/">Maven Repository</a>  搜索<code>Spring</code> 选择 <code>Spring Web MVC</code></p>
<p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210916215312.png" alt="image-20210916215312155"></p>
<p>相关代码如下：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-webmvc<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>5.2.9.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-jdbc<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">version</span>&gt;</span>5.2.9.RELEASE<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="2-两个核心-控制反转（IOC）、面向切面编程（AOP）"><a href="#2-两个核心-控制反转（IOC）、面向切面编程（AOP）" class="headerlink" title="2. 两个核心-控制反转（IOC）、面向切面编程（AOP）"></a>2. 两个核心-控制反转（IOC）、面向切面编程（AOP）</h2><p>== 总结：Spring 是一个轻量级的控制反转和面向切面编程的框架 ==</p>
<h3 id="2-1-IOC理论"><a href="#2-1-IOC理论" class="headerlink" title="2.1 IOC理论"></a>2.1 IOC理论</h3><h4 id="2-1-1-简单实例理解IOC设计理念"><a href="#2-1-1-简单实例理解IOC设计理念" class="headerlink" title="2.1.1 简单实例理解IOC设计理念"></a>2.1.1 简单实例理解IOC设计理念</h4><p><a target="_blank" rel="noopener" href="https://gitee.com/berlinwong/spring5/tree/master/01-spring-ioc">第一段 简单了解IoC</a>  对象由Spring创建、管理、装配</p>
<p><a target="_blank" rel="noopener" href="https://gitee.com/berlinwong/spring5/tree/master/02-spring-ioc-review">第二段 复习</a></p>
<h4 id="2-1-2-三种构造器注入方式"><a href="#2-1-2-三种构造器注入方式" class="headerlink" title="2.1.2 三种构造器注入方式"></a>2.1.2 三种构造器注入方式</h4><ol>
<li>下标赋值</li>
<li>类型赋值</li>
<li>name赋值</li>
</ol>
<p><a target="_blank" rel="noopener" href="https://gitee.com/berlinwong/spring5/tree/master/03-spring-constructor-01">三种赋值方法案例</a></p>
<h3 id="2-2-Spring-配置"><a href="#2-2-Spring-配置" class="headerlink" title="2.2 Spring 配置"></a>2.2 Spring 配置</h3><h4 id="2-2-1-别名"><a href="#2-2-1-别名" class="headerlink" title="2.2.1 别名"></a>2.2.1 别名</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">alias</span> <span class="attr">name</span>=<span class="string">&quot;user&quot;</span> <span class="attr">alias</span>=<span class="string">&quot;userBerlin&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-2-2-Bean配置"><a href="#2-2-2-Bean配置" class="headerlink" title="2.2.2 Bean配置"></a>2.2.2 Bean配置</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">    id：bean的唯一标识符，相当于对象名</span></span><br><span class="line"><span class="comment">    class：bean所对应的全限定名（包名 + 类型）</span></span><br><span class="line"><span class="comment">    name：也是别名，而且可以同时取多个别名</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;user&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.top.User&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">type</span>=<span class="string">&quot;java.lang.String&quot;</span> <span class="attr">value</span>=<span class="string">&quot;Berlin&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="2-2-3-import"><a href="#2-2-3-import" class="headerlink" title="2.2.3 import"></a>2.2.3 import</h4><p>将多个配置文件合并为一个</p>
<h3 id="2-3-依赖注入（DI）"><a href="#2-3-依赖注入（DI）" class="headerlink" title="2.3 依赖注入（DI）"></a>2.3 依赖注入（DI）</h3><p><span style="background-color:#d09457;color:black;">依赖注入的本质是Set注入！</span></p>
<p>依赖：Bean对象的所有创建依赖容器。</p>
<p>注入：Bean对象的所有属性由容器注入。</p>
<h4 id="2-3-1-构造器注入"><a href="#2-3-1-构造器注入" class="headerlink" title="2.3.1 构造器注入"></a>2.3.1 构造器注入</h4><p>​    [见：2.1.2 三种构造器注入方式](#2.1.2 三种构造器注入方式)</p>
<h4 id="2-3-2-Set方式注入"><a href="#2-3-2-Set方式注入" class="headerlink" title="2.3.2 Set方式注入"></a>2.3.2 Set方式注入</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--普通注入--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;address&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.di.Address&quot;</span> &gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;address&quot;</span> <span class="attr">value</span>=<span class="string">&quot;宿迁&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;student&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.di.Student&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;name&quot;</span> <span class="attr">value</span>=<span class="string">&quot;Berlin&quot;</span>/&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--Bean注入，ref--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;address&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;address&quot;</span>/&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--数组注入ref--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;books&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">array</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>西游记<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>红楼梦<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>水浒传<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>三国演义<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">array</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--list--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;hobbys&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">list</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>读书<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>读新闻<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>书法<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">list</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--map--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;card&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">map</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;IDCard&quot;</span> <span class="attr">value</span>=<span class="string">&quot;1233211234567&quot;</span> /&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;studentCard&quot;</span> <span class="attr">value</span>=<span class="string">&quot;1233534&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">map</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">&lt;!--set--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;games&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">set</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>LOL<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">value</span>&gt;</span>王者荣耀<span class="tag">&lt;/<span class="name">value</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--null--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;wife&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">null</span> /&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;info&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">props</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">prop</span> <span class="attr">key</span>=<span class="string">&quot;sno&quot;</span>&gt;</span>213123123123<span class="tag">&lt;/<span class="name">prop</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">prop</span> <span class="attr">key</span>=<span class="string">&quot;sname&quot;</span>&gt;</span>Berlin<span class="tag">&lt;/<span class="name">prop</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">props</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h4 id="2-3-3-第三方注入（拓展注入）"><a href="#2-3-3-第三方注入（拓展注入）" class="headerlink" title="2.3.3 第三方注入（拓展注入）"></a>2.3.3 第三方注入（拓展注入）</h4><p>p-namespace &amp; c-namespace</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;user&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.di.Address&quot;</span> <span class="attr">p:address</span>=<span class="string">&quot;Berlin&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;student&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.di.Student&quot;</span> <span class="attr">c:name</span>=<span class="string">&quot;berlin&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-3-4-Bean-scopes"><a href="#2-3-4-Bean-scopes" class="headerlink" title="2.3.4 Bean scopes"></a>2.3.4 Bean scopes</h4><p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923141949.png" alt="image-20210923141944236"></p>
<p>what is ‘The Singleton Scope’？</p>
<h5 id="1-The-Singleton-Scope-单例模式"><a href="#1-The-Singleton-Scope-单例模式" class="headerlink" title="1. The Singleton Scope 单例模式"></a>1. The Singleton Scope 单例模式</h5><p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923142417.png" alt="image-20210923142417050"></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;accountService&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.something.DefaultAccountService&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- the following is equivalent, though redundant (singleton scope is the default) --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;accountService&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.something.DefaultAccountService&quot;</span> <span class="attr">scope</span>=<span class="string">&quot;singleton&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>



<h5 id="2-The-Prototype-Scope-原型模式"><a href="#2-The-Prototype-Scope-原型模式" class="headerlink" title="2. The Prototype Scope 原型模式"></a>2. The Prototype Scope 原型模式</h5><p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923142711.png" alt="image-20210923142711912"></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;accountService&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.something.DefaultAccountService&quot;</span> <span class="attr">scope</span>=<span class="string">&quot;prototype&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="2-4-Bean-自动装配"><a href="#2-4-Bean-自动装配" class="headerlink" title="2.4 Bean 自动装配"></a>2.4 Bean 自动装配</h3><ol>
<li>在xml中装配</li>
<li>在java中显示</li>
<li>隐式的自动装配【！重要  】</li>
</ol>
<p> <a target="_blank" rel="noopener" href="https://gitee.com/berlinwong/spring5/tree/master/05-spring-autowired">一人两宠物-环境代码</a></p>
<h4 id="2-4-1-Autowired-ByName"><a href="#2-4-1-Autowired-ByName" class="headerlink" title="2.4.1 Autowired - ByName"></a>2.4.1 Autowired - ByName</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;human&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.top.Human&quot;</span> <span class="attr">autowire</span>=<span class="string">&quot;byName&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="2-4-2-Autowired-ByType"><a href="#2-4-2-Autowired-ByType" class="headerlink" title="2.4.2 Autowired - ByType"></a>2.4.2 Autowired - ByType</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;human&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.berlin.top.Human&quot;</span> <span class="attr">autowire</span>=<span class="string">&quot;byType&quot;</span>/&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="2-5-注解实现自动装配"><a href="#2-5-注解实现自动装配" class="headerlink" title="2.5 注解实现自动装配"></a>2.5 注解实现自动装配</h3><h4 id="2-5-1-使用"><a href="#2-5-1-使用" class="headerlink" title="2.5.1 使用"></a>2.5.1 使用</h4><h5 id="1-导入Context约束"><a href="#1-导入Context约束" class="headerlink" title="1. 导入Context约束"></a>1. 导入Context约束</h5><h5 id="2-配置注解的支持-lt-context-annotation-config-gt"><a href="#2-配置注解的支持-lt-context-annotation-config-gt" class="headerlink" title="2. 配置注解的支持&lt;context:annotation-config/&gt;"></a>2. 配置注解的支持<code>&lt;context:annotation-config/&gt;</code></h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">&quot;http://www.springframework.org/schema/beans&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:c</span>=<span class="string">&quot;http://www.springframework.org/schema/c&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:p</span>=<span class="string">&quot;http://www.springframework.org/schema/p&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:context</span>=<span class="string">&quot;http://www.springframework.org/schema/context&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:xsi</span>=<span class="string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span></span><br><span class="line"><span class="tag">       <span class="attr">xsi:schemaLocation</span>=<span class="string">&quot;http://www.springframework.org/schema/beans</span></span></span><br><span class="line"><span class="string"><span class="tag">                           http://www.springframework.org/schema/beans/spring-beans.xsd</span></span></span><br><span class="line"><span class="string"><span class="tag">                           http://www.springframework.org/schema/context</span></span></span><br><span class="line"><span class="string"><span class="tag">                           http://www.springframework.org/schema/context/spring-context.xsd&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">context:annotation-config</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h5 id="3-Component-衍生注解"><a href="#3-Component-衍生注解" class="headerlink" title="3. @Component 衍生注解"></a>3. @Component 衍生注解</h5><ul>
<li>按照MVC三层架构我们一般：<ul>
<li>dao【@Repository】</li>
<li>service【@Service】</li>
<li>controller【@Controller】</li>
</ul>
</li>
</ul>
<p>四个作用是一样的，都是相当于把某个类注册到Spring容器中，装配Bean。</p>
<h5 id="4-自动装配"><a href="#4-自动装配" class="headerlink" title="4. 自动装配"></a>4. 自动装配</h5><p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923212111.png" alt="image-20210923212111296"></p>
<h5 id="5-作用域"><a href="#5-作用域" class="headerlink" title="5. 作用域"></a>5. 作用域</h5><ul>
<li><code>@Scope(&quot;singleton&quot;)</code> 单例模式</li>
<li><code>@Scope(&quot;prototype&quot;)</code> 原型模式</li>
</ul>
<h5 id="6-JavaConfig"><a href="#6-JavaConfig" class="headerlink" title="6. JavaConfig"></a>6. JavaConfig</h5><p><img src="https://gitee.com/berlinwong/picgo/raw/master/img/20210923233829.png" alt="截屏2021-09-23 下午11.24.49"></p>
<p><code>User.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Value(&quot;berlin&quot;)</span></span><br><span class="line">  <span class="keyword">private</span> String name;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>UserConfig.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserConfig</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Bean</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> User <span class="title">user</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> User();</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>Test</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyTestIn7</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Test</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test</span><span class="params">()</span></span>&#123;</span><br><span class="line">    ApplicationContext context = <span class="keyword">new</span> AnnotationConfigApplicationContext(UserConfig.class);</span><br><span class="line">    User user = context.getBean(<span class="string">&quot;user&quot;</span>, User.class);</span><br><span class="line">    System.out.println(user.getName());</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-面向切面编程（AOP"><a href="#3-面向切面编程（AOP" class="headerlink" title="3. 面向切面编程（AOP)"></a>3. 面向切面编程（AOP)</h2><p>代理模式</p>
<h3 id="3-1-静态代理"><a href="#3-1-静态代理" class="headerlink" title="3.1 静态代理"></a>3.1 静态代理</h3><p>角色分析：</p>
<ul>
<li>抽象角色</li>
<li>真实角色</li>
<li>代理角色</li>
<li>客户</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://gitee.com/berlinwong/spring5/tree/master/08-spring-staticProxy">代码环境</a></p>
<h3 id="3-2-动态代理"><a href="#3-2-动态代理" class="headerlink" title="3.2 动态代理"></a>3.2 动态代理</h3><h3 id="3-3-AOP-高雅的动态代理"><a href="#3-3-AOP-高雅的动态代理" class="headerlink" title="3.3 AOP - 高雅的动态代理"></a>3.3 AOP - 高雅的动态代理</h3><p>呜呜呜… 留个坑后面再补吧…</p>

      
    </div>
    
    
    
    
      <div style="text-align:center;color: #634db5;font-size:12px;">
-------------  本文结束 <i class="fa fa-cog fa-spin fa-1x fa-fw"></i> 感谢阅读  -------------
</div>

    
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/berlinblog/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
          
            <a href="/berlinblog/tags/Spring/" rel="tag"><i class="fa fa-tag"></i> Spring</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/berlinblog/2021/09/12/%E6%B5%85%E6%9E%90Servlet/" rel="next" title="浅尝Servlet">
                <i class="fa fa-chevron-left"></i> 浅尝Servlet
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/berlinblog/2021/09/25/MyBatis/" rel="prev" title="MyBatis 指北 第一章">
                MyBatis 指北 第一章 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/berlinblog/images/avatar.png"
               alt="" />
          <p class="site-author-name" itemprop="name"></p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/berlinblog/archives/">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/berlinblog/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/berlinblog/tags/index.html">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/berlinblog/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://gitee.com/berlinwong" target="_blank" title="Gitee">
                  
                    <i class="fa fa-fw fa-git"></i>
                  
                    
                      Gitee
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="wzysws@gmail.com" target="_blank" title="E-Mail">
                  
                    <i class="fa fa-fw fa-envelope"></i>
                  
                    
                      E-Mail
                    
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/berlinblog/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link"><span class="nav-number">1.</span> <span class="nav-text">浅尝Spring 5</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BD%BF%E7%94%A8Maven%E5%AF%BC%E5%85%A5Spring%E5%8C%85"><span class="nav-number">1.1.</span> <span class="nav-text">1. 使用Maven导入Spring包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%B8%A4%E4%B8%AA%E6%A0%B8%E5%BF%83-%E6%8E%A7%E5%88%B6%E5%8F%8D%E8%BD%AC%EF%BC%88IOC%EF%BC%89%E3%80%81%E9%9D%A2%E5%90%91%E5%88%87%E9%9D%A2%E7%BC%96%E7%A8%8B%EF%BC%88AOP%EF%BC%89"><span class="nav-number">1.2.</span> <span class="nav-text">2. 两个核心-控制反转（IOC）、面向切面编程（AOP）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-IOC%E7%90%86%E8%AE%BA"><span class="nav-number">1.2.1.</span> <span class="nav-text">2.1 IOC理论</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-%E7%AE%80%E5%8D%95%E5%AE%9E%E4%BE%8B%E7%90%86%E8%A7%A3IOC%E8%AE%BE%E8%AE%A1%E7%90%86%E5%BF%B5"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">2.1.1 简单实例理解IOC设计理念</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-%E4%B8%89%E7%A7%8D%E6%9E%84%E9%80%A0%E5%99%A8%E6%B3%A8%E5%85%A5%E6%96%B9%E5%BC%8F"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">2.1.2 三种构造器注入方式</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-Spring-%E9%85%8D%E7%BD%AE"><span class="nav-number">1.2.2.</span> <span class="nav-text">2.2 Spring 配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-%E5%88%AB%E5%90%8D"><span class="nav-number">1.2.2.1.</span> <span class="nav-text">2.2.1 别名</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-Bean%E9%85%8D%E7%BD%AE"><span class="nav-number">1.2.2.2.</span> <span class="nav-text">2.2.2 Bean配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-3-import"><span class="nav-number">1.2.2.3.</span> <span class="nav-text">2.2.3 import</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%EF%BC%88DI%EF%BC%89"><span class="nav-number">1.2.3.</span> <span class="nav-text">2.3 依赖注入（DI）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E6%9E%84%E9%80%A0%E5%99%A8%E6%B3%A8%E5%85%A5"><span class="nav-number">1.2.3.1.</span> <span class="nav-text">2.3.1 构造器注入</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-Set%E6%96%B9%E5%BC%8F%E6%B3%A8%E5%85%A5"><span class="nav-number">1.2.3.2.</span> <span class="nav-text">2.3.2 Set方式注入</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-3-%E7%AC%AC%E4%B8%89%E6%96%B9%E6%B3%A8%E5%85%A5%EF%BC%88%E6%8B%93%E5%B1%95%E6%B3%A8%E5%85%A5%EF%BC%89"><span class="nav-number">1.2.3.3.</span> <span class="nav-text">2.3.3 第三方注入（拓展注入）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-4-Bean-scopes"><span class="nav-number">1.2.3.4.</span> <span class="nav-text">2.3.4 Bean scopes</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-The-Singleton-Scope-%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F"><span class="nav-number">1.2.3.4.1.</span> <span class="nav-text">1. The Singleton Scope 单例模式</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-The-Prototype-Scope-%E5%8E%9F%E5%9E%8B%E6%A8%A1%E5%BC%8F"><span class="nav-number">1.2.3.4.2.</span> <span class="nav-text">2. The Prototype Scope 原型模式</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-Bean-%E8%87%AA%E5%8A%A8%E8%A3%85%E9%85%8D"><span class="nav-number">1.2.4.</span> <span class="nav-text">2.4 Bean 自动装配</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-1-Autowired-ByName"><span class="nav-number">1.2.4.1.</span> <span class="nav-text">2.4.1 Autowired - ByName</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-2-Autowired-ByType"><span class="nav-number">1.2.4.2.</span> <span class="nav-text">2.4.2 Autowired - ByType</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E6%B3%A8%E8%A7%A3%E5%AE%9E%E7%8E%B0%E8%87%AA%E5%8A%A8%E8%A3%85%E9%85%8D"><span class="nav-number">1.2.5.</span> <span class="nav-text">2.5 注解实现自动装配</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-5-1-%E4%BD%BF%E7%94%A8"><span class="nav-number">1.2.5.1.</span> <span class="nav-text">2.5.1 使用</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-%E5%AF%BC%E5%85%A5Context%E7%BA%A6%E6%9D%9F"><span class="nav-number">1.2.5.1.1.</span> <span class="nav-text">1. 导入Context约束</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-%E9%85%8D%E7%BD%AE%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%94%AF%E6%8C%81-lt-context-annotation-config-gt"><span class="nav-number">1.2.5.1.2.</span> <span class="nav-text">2. 配置注解的支持&lt;context:annotation-config&#x2F;&gt;</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-Component-%E8%A1%8D%E7%94%9F%E6%B3%A8%E8%A7%A3"><span class="nav-number">1.2.5.1.3.</span> <span class="nav-text">3. @Component 衍生注解</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-%E8%87%AA%E5%8A%A8%E8%A3%85%E9%85%8D"><span class="nav-number">1.2.5.1.4.</span> <span class="nav-text">4. 自动装配</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#5-%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="nav-number">1.2.5.1.5.</span> <span class="nav-text">5. 作用域</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#6-JavaConfig"><span class="nav-number">1.2.5.1.6.</span> <span class="nav-text">6. JavaConfig</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%9D%A2%E5%90%91%E5%88%87%E9%9D%A2%E7%BC%96%E7%A8%8B%EF%BC%88AOP"><span class="nav-number">1.3.</span> <span class="nav-text">3. 面向切面编程（AOP)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E9%9D%99%E6%80%81%E4%BB%A3%E7%90%86"><span class="nav-number">1.3.1.</span> <span class="nav-text">3.1 静态代理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86"><span class="nav-number">1.3.2.</span> <span class="nav-text">3.2 动态代理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-AOP-%E9%AB%98%E9%9B%85%E7%9A%84%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86"><span class="nav-number">1.3.3.</span> <span class="nav-text">3.3 AOP - 高雅的动态代理</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-ravelry"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Berlin</span>
</div>



        

        
      </div>
    </footer>

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/berlinblog/libs/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/berlinblog/libs/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/berlinblog/libs/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/berlinblog/libs/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/berlinblog/libs/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/berlinblog/libs/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/berlinblog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/berlinblog/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/berlinblog/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/berlinblog/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/berlinblog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/berlinblog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/berlinblog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
</html>
